package babo.cd.physicalexperiment.activity;

import android.graphics.Color;
import android.view.View;

import androidx.fragment.app.Fragment;
import androidx.viewpager.widget.ViewPager;

import java.util.ArrayList;

import babo.cd.physicalexperiment.BaseActivity;
import babo.cd.physicalexperiment.R;
import babo.cd.physicalexperiment.adapter.MainViewPageAdapter;
import babo.cd.physicalexperiment.app.MyApplication;
import babo.cd.physicalexperiment.databinding.ActivityShebeilistmanagerBinding;
import babo.cd.physicalexperiment.fragment.SheBeiFragmentListFragment;
import babo.cd.physicalexperiment.fragment.ShiyanHistoryListFragment;

public class ShiyanHistoryiListActivity extends BaseActivity {
    ActivityShebeilistmanagerBinding binding;

    private ArrayList<Fragment> mFragments;
    private MainViewPageAdapter mAdapter;
    private ShiyanHistoryListFragment sheBeiFragmentMkex;
    private ShiyanHistoryListFragment sheBeiFragmentZylt;
    @Override
    protected View bindView() {
        binding=ActivityShebeilistmanagerBinding.inflate(getLayoutInflater());
        return binding.getRoot();
    }

    @Override
    protected void initView() {

    }

    @Override
    public void rightClick() {
        super.rightClick();
        goToNextActivity(AddDeviceActivity.class);
    }

    @Override
    protected void loadData() {
        binding.topbar.setCenterText("实验记录");
        mFragments = new ArrayList<>();
        String role= MyApplication.getInstance().getUserBaseInfo().getRole().toUpperCase();
        boolean isadmin=false;
        if (role.contains("ADMIN")){
            isadmin=true;
        }

        sheBeiFragmentMkex = new ShiyanHistoryListFragment(1,isadmin);
        sheBeiFragmentZylt = new ShiyanHistoryListFragment(2,isadmin);
        mFragments.add(sheBeiFragmentMkex);
        mFragments.add(sheBeiFragmentZylt);




        mAdapter = new MainViewPageAdapter(ShiyanHistoryiListActivity.this, mFragments, getSupportFragmentManager());
        binding.vpp.setAdapter(mAdapter);
        binding.vpp.setOffscreenPageLimit(2);
    }

    @Override
    protected void onDestroy() {
        super.onDestroy();

    }

    @Override
    public void setListener() {
        super.setListener();
        binding.llLeft.setOnClickListener(v -> binding.vpp.setCurrentItem(0));
        binding.llRight.setOnClickListener(v -> binding.vpp.setCurrentItem(1));
        binding.vpp.addOnPageChangeListener(new ViewPager.OnPageChangeListener() {
            @Override
            public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {

            }

            @Override
            public void onPageSelected(int position) {
              checkT(position);
            }

            @Override
            public void onPageScrollStateChanged(int state) {

            }
        });

    }
    private void checkT(int posion){
        if (posion==0){
            binding.txLeft.setTextColor(getResources().getColor(R.color.blue));
            binding.vLeft.setVisibility(View.VISIBLE);
            binding.txRight.setTextColor(Color.parseColor("#999999"));
            binding.vRight.setVisibility(View.INVISIBLE);
        }else{
            binding.txRight.setTextColor(getResources().getColor(R.color.blue));
            binding.vRight.setVisibility(View.VISIBLE);
            binding.txLeft.setTextColor(Color.parseColor("#999999"));
            binding.vLeft.setVisibility(View.INVISIBLE);
        }
    }
}
